'Copyright (c) 2007, Code Endeavors, LLC - 'http://www.codeendeavors.com
'This source is subject to the BSD License.
'See http://www.opensource.org/licenses/bsd-license.php

Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection

Imports DotNetNuke
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.UI.Utilities

Namespace $YourCompany$.Modules.$safeprojectname$

    <ControlMethodClass("$YourCompany$.Modules.$safeprojectname$.View$safeprojectname$")> _
    Partial Class View$safeprojectname$
        Inherits AjaxPortalModuleBase
        Implements Entities.Modules.IActionable

#Region "AjaxPortalModuleBase Events"
        '-------------------------------------------------------------------------------------------------------------
        '- This is where you add your custom properties that are to be sent down to the client-side object
        '- By default we are passing the naming container ID (ns) and localized messages (msgs) 
        '- If you add your own properties make sure you update your client code with those properties found in Edit$safeprojectname$.ascx.js
        '-      get_ImagePath: function() {return this._imagePath;},
        '-      set_ImagePath: function(value) {this._imagePath = value;},
        '-------------------------------------------------------------------------------------------------------------
        Protected Sub AjaxPortalModuleBase_AddScriptComponentDescriptors(ByVal Descriptor As ScriptComponentDescriptor) Handles MyBase.AddScriptComponentDescriptors
            'IMPORTANT!  Enter Client Namespace + ObjectName as Type
            Descriptor.Type = "$YourCompany$.View$safeprojectname$"

            '---------------------------------------------------------------------------------------------------------
            'Add custom properties here
            '   Descriptor.AddScriptProperty("ImagePath", String.Format("'{0}'", Me.ModulePath & "images/"))
            '---------------------------------------------------------------------------------------------------------
        End Sub

        '-------------------------------------------------------------------------------------------------------------
        '- This is where your client-side javascript that uses the MS AJAX framework needs to be registered
        '- Adding the reference here ensures that the MS AJAX script is run before our script which uses things like Type.registerNamespace run
        '-------------------------------------------------------------------------------------------------------------
        Protected Sub AjaxPortalModuleBase_AddScriptReferences(ByVal References As List(Of ScriptReference)) Handles MyBase.AddScriptReferences
            References.Add(New System.Web.UI.ScriptReference(Me.ModulePath & "View$safeprojectname$.ascx.js"))
        End Sub

        '-------------------------------------------------------------------------------------------------------------
        '- Add any localized text needed on the client
        '-------------------------------------------------------------------------------------------------------------
        Protected Sub AjaxPortalModuleBase_AddLocalizedMessages(ByVal Messages As Dictionary(Of String, String)) Handles MyBase.AddLocalizedMessages
            Messages("btnHello") = Localization.GetString("btnHello.Client", LocalResourceFile)
        End Sub

#End Region

#Region "Event Handlers"

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                If Settings.ContainsKey("Name") Then
                    lblName.Text = CStr(Settings("Name"))
                End If
                If Settings.ContainsKey("Desc") Then
                    lblDesc.Text = CStr(Settings("Desc"))
                End If

            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

#Region "Control Methods"
        '-------------------------------------------------------------------------------------------------------------
        '- Exposing methods to the client code is as simple as adding the ControlMethod attribute
        '- IMPORTANT!   ALWAYS SECURE YOUR CONTROL METHODS IF INTERACTING WITH SENSITIVE DATA
        '-------------------------------------------------------------------------------------------------------------
        <ControlMethod()> _
        Public Function Hello(ByVal Name As String, ByVal Description As String) As String
            Return String.Format("Hello {0}, your description was submitted at {1}", Name, Now.ToString())
        End Function
#End Region


#Region "Optional Interfaces"

        ' Registers the module actions required for interfacing with the portal framework
        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
                Actions.Add(GetNextActionID, Localization.GetString("Edit.Text", LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), False, Security.SecurityAccessLevel.Edit, True, False)
                Return Actions
            End Get
        End Property

#End Region

    End Class

End Namespace
